""" System imports """
import logging
import pygame

""" Equinox """
import eventrouter
from events import *

""" Constants """

""" Set up logging """
_log = logging.getLogger("epicquest.keyboardcontroller")

class KeyboardController:
    """ Class to control keyboard events """
        
    def __init__(self, evManager):
        self.evManager = evManager
        self.evManager.registerListener(self)
        
    def notify(self, event):
        if isinstance( event, TickEvent ):
            #Handle Input Events
            for event in pygame.event.get():
                ev = None
                if event.type == pygame.QUIT:
                    ev = QuitEvent()
                elif event.type == pygame.KEYDOWN \
                     and event.key == pygame.K_ESCAPE:
                    ev = QuitEvent()
                elif event.type == pygame.KEYDOWN:
                    ev = KeyPressedEvent(event)
                elif event.type == pygame.KEYUP:
                    ev = KeyReleasedEvent(event)
                if ev:
                    self.evManager.post( ev )
